package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.RecordCourseLack;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 记上课先扣课时，金额保存 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2023-05-19
 */
public interface RecordCourseLackMapper extends BaseMapper<RecordCourseLack> {

    @Select("SELECT IFNULL( SUM( a.buckle_class_money ), 0 ) AS buckle_class_money FROM record_course_lack as a LEFT JOIN record_course as b on a.id = b.id WHERE a.order_detail_id = ${orderDetailId} AND a.deleted = 0 AND a.is_deduct_money = 0 and b.is_repair <>1 and b.`status` <>1 and b.is_deduct_money = 0")
    public BigDecimal getAllBucklemoneyForOrderDetailId(@Param("orderDetailId") Long orderDetailId);


    @Select("SELECT\n" +
            "\ta.buckle_class_money,a.order_detail_id \n" +
            "FROM\n" +
            "\trecord_course_lack AS a\n" +
            "\tLEFT JOIN order_detail AS b ON a.order_detail_id = b.id\n" +
            "\tLEFT JOIN record_course AS c ON a.id = c.id \n" +
            "WHERE\n" +
            "\tb.residue_course_count = 0 \n" +
            "\tAND b.residue_price = 0 \n" +
            "\tAND a.is_deduct_money = 0 \n" +
            "\tAND c.is_repair <>1\n" +
            "\tAND c.`status` =2\n" +
            "\tand a.deleted = 0\n" +
            "\tand c.deleted = 0\n" +
            "\tand b.deleted = 0\n" +
            "\tand a.buckle_class_money>0\n" +
            "\tORDER BY a.buckle_class_money DESC")
    public List<RecordCourseLack> getTestList();

}
